package common

import "github.com/gin-gonic/gin"

type JsonStruct struct {
	Code  int         `json:"code"`
	Msg   interface{} `gorm:"" json:"msg"`
	Data  interface{} `gorm:"" json:"data"`
	Count int64       `gorm:"" json:"count"`
}

type JsonStruct1 struct {
	Code int         `json:"code"`
	Msg  interface{} `gorm:"" json:"msg"`
	Data interface{} `gorm:"" json:"data"`
}

// 通用的树形结构
type Ztree struct {
	Id      int64  `json:"id"`      //节点ID
	Pid     int64  `json:"pId"`     //节点父ID
	Name    string `json:"name"`    //节点名称
	Title   string `json:"title"`   //节点标题
	Checked bool   `json:"checked"` //是否勾选
	Open    bool   `json:"open"`    //是否展开
	Nocheck bool   `json:"nocheck"` //是否能勾选
}

//登录接口返回格式
type JsonLoginRestful struct {
	Code  int         `gorm:"" json:"code"`  // 'json: "code"'
	Msg   interface{} `gorm:"" json:"msg"`   //'json: "msg"'
	Token interface{} `gorm:"" json:"token"` //'json: "token"'
}

//geInfo
type JsonGetInfo struct {
	Code        int         `gorm:"" json:"code"`        //`json:"code"`  //后面定义  是接口返回的字段格式，默认不加后面格式的话，默认返回首字母大写
	Msg         interface{} `gorm:"" json:"msg"`         //`json:"msg"`
	Permissions interface{} `gorm:"" json:"permissions"` //`json:"permissions"`
	Roles       interface{} `gorm:"" json:"roles"`       //`json:"roles"`
	User        interface{} `gorm:"" json:"user"`        //`json:"user"`
}

type JsonListStruct struct {
	Code  int         `gorm:"" json:"code"`
	Msg   interface{} `gorm:"" json:"msg"`
	Rows  interface{} `gorm:"" json:"rows"`
	Total int64       `gorm:"" json:"total"`
}

//通用接口请求成功放回格式返回
func ReturnSucess(c *gin.Context, code int, msg interface{}, data interface{}, count int64) {
	json := &JsonStruct{Code: code, Msg: msg, Data: data, Count: count}
	c.JSON(200, json)
}

//通用接口请求成功放回格式返回
func ReturnSucess1(c *gin.Context, code int, msg interface{}, data interface{}) {
	json := &JsonStruct1{Code: code, Msg: msg, Data: data}
	c.JSON(200, json)
}

//登录成功返回的接口格式c
func ReturnLoginSucess(c *gin.Context, code int, msg interface{}, token interface{}) {
	json := &JsonLoginRestful{Code: code, Msg: msg, Token: token}
	c.JSON(200, json)
}

//getInfo 接口请求成功放回格式返回
func ReturnGetInfoSucess(c *gin.Context, code int, msg interface{}, permissions interface{}, roles interface{}, user interface{}) {
	json := &JsonGetInfo{Code: code, Msg: msg, Permissions: permissions, Roles: roles, User: user}
	c.JSON(200, json)
}

func ReturnError(c *gin.Context, code int, msg interface{}, data interface{}, count int64) {
	json := &JsonStruct{Code: code, Msg: msg, Data: data, Count: count}
	c.JSON(200, json)
}

//列表接口成功返回
func ReturnListSucess(c *gin.Context, code int, msg interface{}, rows interface{}, total int64) {
	json := &JsonListStruct{Code: code, Msg: msg, Rows: rows, Total: total}
	c.JSON(200, json)
}
